/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sistema.tools;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.swing.JOptionPane;

/**
 *
 * @author gr
 */
public class Md5
{

    public static String md5( String senha ) throws NoSuchAlgorithmException
    {

        MessageDigest md = MessageDigest.getInstance( "MD5" );

        BigInteger hash = new BigInteger( 1, md.digest( senha.getBytes() ) );

        return "<" + hash.toString( 16 ) + ">";

    }

    public static void main( String args[] )
    {
        String senha = JOptionPane.showInputDialog( null, "Digite uma senha: ");

        if ( ( senha.equalsIgnoreCase( "" ) == false ) && ( senha.length() <= 16 ) )
        {
            try
            {
                System.out.println( "Senha MD5: " + md5( senha ) );
            } catch ( Exception e )
            {
                System.out.println( "Erro ao gerar criptografia!" );
            }
        }
    }
}
